package com.tuu.utils;

import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;
@Data
public  class BrowerUtils {
    private String browserName;
    private String operatingSystem;
    private String browserVersion;

    public static BrowerUtils getBrowerInfo(HttpServletRequest request){
        UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
        Browser browser = userAgent.getBrowser();
        OperatingSystem operatingSystem = userAgent.getOperatingSystem();
        Version browserVersion = userAgent.getBrowserVersion();
        BrowerUtils bu=new BrowerUtils();
        bu.setBrowserName(browser.getName());
        bu.setOperatingSystem(operatingSystem.getName());
        bu.setBrowserVersion(browserVersion.getVersion());

        return bu;
    }

}
